<?php
namespace Admin\Controller;

class CommonController extends AdminController {
	Public function getSchoolList($map = array(), $field = true){
		$l = array();
		$l = D('School')->where($map)->field($field)->select();
		return $l;
	}
	
	Public function getXiList($map = array(), $field = true){
		$l = array();
		$l = D('Xi')->where($map)->field($field)->select();
		return $l;
	}
	
	Public function getNianjiList($map = array(), $field = true){
		$l = array();
		$l = D('Nianji')->where($map)->field($field)->select();
		return $l;
	}
	
	Public function getBanjiList($map = array(), $field = true){
		$l = array();
		$l = D('Banji')->where($map)->field($field)->select();
		return $l;
	}
	
	Public function getQrcodeCates($map = array(), $field = true){
		$l = array();
		$l = D('QrcodeCategory')->where($map)->field($field)->select();
		return $l;
	}
	
	Public function getBuildings($schoolId = 0, $field = true){
		$l = array();
		if ($schoolId > 0) {
			$map['school_id'] = $schoolId;
			$l = D('Building')->where($map)->field($field)->select();
		}
		return $l;
	}
	
	Public function getBuildingsAjax(){
		$l = array();
		$schoolId = I('get.school_id') > 0 ? I('get.school_id') : 0;
		if ($schoolId > 0) {
			$map['school_id'] = $schoolId;
			$l = D('Building')->where($map)->field('id,title')->select();
		}
		echo $this->_genSelect($l, 'building_id');
	}
	
	private function _genSelect($data, $name, $current = 0){
		$str = "<select name='" . $name . "'>";
		$str .= "<option value='0'>请选择</option>";
		if (!empty($data)) {
			foreach ($data as $record){
				$str .= "<option value='" . $record['id'] . "'";
				$str .= $current == $record['id'] ? "selected='selected'" : "";
				$str .= ">" . $record['title'] . "</option>";
			}
		}
		$str .= "</select>";
		return $str;
	}

}